<?php
$port1 = "";
$connection1 = "";
$port2 = "";
$connection2 = "";
?>
<head>
<!--[if lt IE 9]>
<script src="asset/js/html5.js"></script>
<script src="asset/js/PIE.js"></script>
<![endif]-->
<!-- jquerytools -->
<script src="<?php echo base_url();?>asset/js/jquery.tools.min.js"></script>
<script src="<?php echo base_url();?>asset/js/jquery.ui.min.js"></script>

<!--[if lte IE 9]>
<link rel="stylesheet" media="screen" href="asset/css/ie.css" />
<script type="text/javascript" src="asset/js/ie.js"></script>
<![endif]-->



</head>
		<header><h2><?php echo 'Setting Device' ?></h2></header>		
<?php
$handle = @fopen("gammurc", "r");
$baris = array();
$i = 1;
$j = 1;
if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle);
        if (substr_count($buffer, 'port = ') > 0)
		{
		   if ($i == 1)
		   {
		      $split = explode("port = ", $buffer);
		      $port1 = str_replace(":", "", $split[1]);
		   }
		   
		   if ($i == 2)
		   {
		      $split = explode("port = ", $buffer);
		      $port2 = str_replace(":", "", $split[1]);
		   }
		   
		   if ($i == 3)
		   {
		      $split = explode("port = ", $buffer);
		      $port3 = str_replace(":", "", $split[1]);
		   }
		   
		   if ($i == 4)
		   {
		      $split = explode("port = ", $buffer);
		      $port4 = str_replace(":", "", $split[1]);
		   }
		   
		   $i++;
		}
		
		if (substr_count($buffer, 'connection = ') > 0)
		{
		   if ($j == 1)
		   {
 		      $split = explode("connection = ", $buffer);
		      $connection1 = $split[1];
		   }
		   
		   if ($j == 2)
		   {
 		      $split = explode("connection = ", $buffer);
		      $connection2 = $split[1];
		   }
		   
		   if ($j == 3)
		   {
 		      $split = explode("connection = ", $buffer);
		      $connection3 = $split[1];
		   }
		   
		   if ($j == 4)
		   {
 		      $split = explode("connection = ", $buffer);
		      $connection4 = $split[1];
		   }
		   
		   $j++;
		}
		
		$baris[] = $buffer; 
    }
    fclose($handle);
}
$id = $this->uri->segment(4);
//echo "uri " . $id;
//if ($_GET['op'] == "simpan")
if ($id == "simpan")
{
  $port1 = $_POST['port1'];
  $connection1 = $_POST['connection1'];
  
  $port2 = $_POST['port2'];
  $connection2 = $_POST['connection2'];

 
  
  $handle = @fopen("gammurc", "w");

  $text = "[gammu]\nport = ".$port1.":\nconnection = ".$connection1."\n[gammu1]\nport = ".$port2.":\nconnection = ".$connection2;
  
  fwrite($handle, $text);
  fclose($handle); 
  echo "<p>Konfigurasi sudah disimpan</p>";  
}else {
	//echo "nono";
}

?> 

<p>Masukkan nomor port dan jenis connection pada form di bawah ini!</p>

<p><b>Modem/HP 1</b></p>

<form method="post" action="<?php echo base_url();?>settings/konfigurasi/1/simpan">
<table>
 <tr><td>PORT</td><td>:</td><td><input type="text" name="port1" value="<?php echo $port1;?>"></td></tr>
 <tr><td>CONNECTION</td><td>:</td><td><input type="text" name="connection1" value="<?php echo $connection1;?>"></td></tr>
</table>

<p><b>Modem/HP 2</b></p>

<table>
 <tr><td>PORT</td><td>:</td><td><input type="text" name="port2" value="<?php echo $port2;?>"></td></tr>
 <tr><td>CONNECTION</td><td>:</td><td><input type="text" name="connection2" value="<?php echo $connection2;?>"></td></tr>
</table>

<input type="submit" name="submit" value="Simpan">
</form>
